const fs = require('fs')
const http = require('http')
const path = require('path')
const server = http.createServer()

server.on('request',( req, res) => {
  if (req.url === '/api/province') {
    fs.readFile(path.join( __dirname + '/city.json'), (err, data) => {
      if (err) return console.log(err);
      JSON.parse(data.toString())
      res.setHeader('Content-Type','')
      res.end(data.toString())
    })
  }
})

server.listen(3001, () => {
  console.log('server running at http://127.0.0.1:3001');
})